// pages/storeDetails/index.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detailsInfo: {},
    imgList: [],
    autoplay: true,
    interval: 3000,
    duration: 1000,
    swiperCurrent:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBranchDetails(options.bid)
  },
  swiperchange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  //门店详情
  getBranchDetails: function (bid) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    wx.request({
      url: app.globalData.host + "/api/Store/GetBranch?bid=" + bid,
      success: function (res) {
        console.log(res)
        wx.hideLoading()
        if (res.data.Code == 0) {
          var imgs = res.data.Data.Imgs;
          var imgList = []
          if (imgs != null) {
             imgList = imgs.split(",")
            for (var i = 0; i < imgList.length; i++) {
              imgList[i] = "https://static.711688.net.cn/upload/store/" + app.globalData.storeId + "/banner/" + imgList[i]
            }
          }
          that.setData({
            detailsInfo: res.data.Data,
            imgList: imgList
          })
          WxParse.wxParse('article', 'html', res.data.Data.Description, that, 5);
          wx.setNavigationBarTitle({
            title: res.data.Data.Name
          })
        }
      },
    })
  },

  //拨打电话
  toCall: function () {
    var phone = this.data.detailsInfo.Phone
    wx.makePhoneCall({
      phoneNumber: phone
    })
  },

  //商家地址导航
  toLocation: function () {
    let location = this.data.detailsInfo.Location;
    if (location) {
      var locationArray = location.split(",")
    }
    let lgtitude = parseFloat(locationArray[0])//纬度
    let lngitude = parseFloat(locationArray[1])//经度
    wx.showModal({
      title: '提示',
      content: '是否确定打开地图导航！',
      success: function (res) {
        if (res.confirm) {
          wx.openLocation({
            latitude: lgtitude,
            longitude: lngitude,
            scale: 28
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})